<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Zookeeper Quorum 机制详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 8px;
            margin-top: 3px;
            font-weight: 700;
            color: #667eea;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .icon-box {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 12px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-size: 24px;
            margin-bottom: 1rem;
        }
        .highlight-box {
            background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
            border-left: 4px solid #667eea;
            padding: 1.5rem;
            margin: 1.5rem 0;
            border-radius: 8px;
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center animate-fadeInUp">
                <h1 class="text-5xl font-bold mb-6">Zookeeper Quorum 机制</h1>
                <p class="text-xl opacity-90 leading-relaxed">深入理解分布式系统中的法定人数机制，确保数据一致性与高可用性</p>
                <div class="mt-8 flex justify-center space-x-6">
                    <div class="flex items-center">
                        <i class="fas fa-server mr-2"></i>
                        <span>分布式协调</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-shield-alt mr-2"></i>
                        <span>数据一致性</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-network-wired mr-2"></i>
                        <span>高可用架构</span>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <div class="max-w-5xl mx-auto">
            
            <!-- Introduction -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="first-letter">在</span>Zookeeper 中，<strong class="text-purple-700">Quorum（法定人数）</strong>是一个关键概念，用于确保集群的一致性和高可用性。它定义了在分布式系统中进行关键操作所需的最小节点数量，是 Zookeeper 实现容错和数据一致性的核心机制。
                </p>
            </div>

            <!-- Quorum Definition -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
                <h2 class="text-3xl font-bold mb-6 section-title">Quorum 的定义</h2>
                <div class="flex items-start">
                    <div class="icon-box mr-6">
                        <i class="fas fa-users"></i>
                    </div>
                    <div class="flex-1">
                        <p class="text-lg leading-relaxed text-gray-700">
                            Quorum 是指在 Zookeeper 集群中，为了进行某些操作（如写入操作或 Leader 选举），需要达到的最小节点数量。这个概念保证了即使部分节点出现故障，Zookeeper 集群依然可以正常工作，且数据的一致性得到保障。
                        </p>
                        <div class="highlight-box mt-4">
                            <p class="text-gray-700"><i class="fas fa-info-circle text-purple-600 mr-2"></i>Quorum = (N / 2) + 1，其中 N 是集群节点总数</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Visual Diagram -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8">
                <h2 class="text-3xl font-bold mb-6 section-title">Quorum 机制可视化</h2>
                <div class="mermaid">
                    graph TB
                        subgraph "5节点集群"
                            L[Leader节点]
                            F1[Follower 1]
                            F2[Follower 2]
                            F3[Follower 3]
                            F4[Follower 4]
                        end
                        
                        subgraph "Quorum = 3"
                            Q1[节点1 ✓]
                            Q2[节点2 ✓]
                            Q3[节点3 ✓]
                        end
                        
                        L -->|写请求| F1
                        L -->|写请求| F2
                        L -->|写请求| F3
                        L -->|写请求| F4
                        
                        F1 -->|确认| Q1
                        F2 -->|确认| Q2
                        F3 -->|确认| Q3
                        
                        Q1 --> S[写操作成功]
                        Q2 --> S
                        Q3 --> S
                        
                        style L fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style S fill:#48bb78,stroke:#fff,stroke-width:2px,color:#fff
                        style Q1 fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                        style Q2 fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                        style Q3 fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>

            <!-- Working Principle -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
                <h2 class="text-3xl font-bold mb-6 section-title">Quorum 的工作原理</h2>
                
                <div class="grid md:grid-cols-2 gap-6">
                    <!-- Write Operations -->
                    <div class="bg-gradient-to-br from-purple-50 to-indigo-50 p-6 rounded-xl">
                        <div class="flex items-center mb-4">
                            <i class="fas fa-pen-to-square text-purple-600 text-2xl mr-3"></i>
                            <h3 class="text-xl font-bold">写操作中的 Quorum</h3>
                        </div>
                        <p class="text-gray-700 leading-relaxed">
                            在 Zookeeper 中，所有写操作都需要通过 Leader 节点进行，然后由 Leader 节点将写请求同步到集群中的 Follower 节点。写操作被认为成功，只有当大多数（Quorum）节点都确认了写请求后，Leader 才会向客户端返回成功响应。
                        </p>
                        <div class="mt-4 p-4 bg-white rounded-lg">
                            <p class="text-sm text-gray-600"><i class="fas fa-lightbulb text-yellow-500 mr-2"></i>例如：5个节点的集群中，Quorum数量是3，写操作需要至少3个节点的确认才能成功。</p>
                        </div>
                    </div>

                    <!-- Leader Election -->
                    <div class="bg-gradient-to-br from-indigo-50 to-purple-50 p-6 rounded-xl">
                        <div class="flex items-center mb-4">
                            <i class="fas fa-crown text-indigo-600 text-2xl mr-3"></i>
                            <h3 class="text-xl font-bold">Leader 选举中的 Quorum</h3>
                        </div>
                        <p class="text-gray-700 leading-relaxed">
                            在 Zookeeper 中，Leader 节点负责处理所有的写请求，并协调集群中的数据同步。Leader 的选举也依赖于 Quorum。为了确保选举过程的正确性，新选举的 Leader 必须获得大多数节点的支持。
                        </p>
                        <div class="mt-4 p-4 bg-white rounded-lg">
                            <p class="text-sm text-gray-600"><i class="fas fa-lightbulb text-yellow-500 mr-2"></i>例如：5个节点的集群中，新的Leader必须获得至少3个节点的同意才能成为Leader。</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Impact on Availability and Consistency -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
                <h2 class="text-3xl font-bold mb-6 section-title">Quorum 对集群可用性和一致性的影响</h2>
                
                <div class="space-y-6">
                    <!-- Data Consistency -->
                    <div class="flex items-start">
                        <div class="bg-green-100 rounded-full p-3 mr-4">
                            <i class="fas fa-check-double text-green-600 text-xl"></i>
                        </div>
                        <div class="flex-1">
                            <h3 class="text-xl font-bold mb-2">数据一致性</h3>
                            <p class="text-gray-700 leading-relaxed">
                                Quorum 确保了数据一致性。当 Quorum 数量的节点都确认了写操作后，数据被认为是一致的。这样可以防止因网络分区或节点故障导致的数据不一致问题。
                            </p>
                        </div>
                    </div>

                    <!-- High Availability -->
                    <div class="flex items-start">
                        <div class="bg-blue-100 rounded-full p-3 mr-4">
                            <i class="fas fa-shield-alt text-blue-600 text-xl"></i>
                        </div>
                        <div class="flex-1">
                            <h3 class="text-xl font-bold mb-2">高可用性</h3>
                            <p class="text-gray-700 leading-relaxed">
                                Quorum 机制提高了 Zookeeper 集群的高可用性。即使集群中部分节点发生故障，只要剩余节点的数量能够达到 Quorum，集群仍然可以继续提供服务。
                            </p>
                        </div>
                    </div>

                    <!-- Network Partition Handling -->
                    <div class="flex items-start">
                        <div class="bg-purple-100 rounded-full p-3 mr-4">
                            <i class="fas fa-network-wired text-purple-600 text-xl"></i>
                        </div>
                        <div class="flex-1">
                            <h3 class="text-xl font-bold mb-2">网络分区处理</h3>
                            <p class="text-gray-700 leading-relaxed">
                                Quorum 机制帮助 Zookeeper 处理网络分区问题。在网络分区的情况下，只有能够达到 Quorum 的节点才会继续提供服务，而其他分区则无法进行写操作或选举新的 Leader。
                            </p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Configuration and Optimization -->
            <div class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
                <h2 class="